import { createLogger } from 'redux-logger';
import { message } from 'antd';
import {getCookies} from './utils/cook'


import { RequestConfig } from 'umi';

//let baseURL="http://123.206.55.50:7002"

let baseURL= "http://localhost:7002"

export const request: RequestConfig = {    //q请求配置
  timeout: 5000,    
  errorConfig: {},
  middlewares: [],
  requestInterceptors: [
    (url, options:any) => {  
      let token=getCookies('token')          
      return {
        url: `${baseURL+url}`,
        options: { ...options, interceptors: true ,headers:{...options.headers,authorization:token}},
      };
    }
  ],
  responseInterceptors: [
    response => {
      const codeMaps:{[key:number]:string} = {
        401:"鉴权失败",
        403:"请求携带信息错误",
        404:"资源不存在",
        500:"服务器错误",
        502: '网关错误。',
        503: '服务不可用，服务器暂时过载或维护。',
        504: '网关超时。',
      };
      if(response.status!==200){
        message.error(codeMaps[response.status]);

      }
      return response;
    }
   ],
};



// export const dva = {    //提示厂库的上一个和下一个状态
//   config: {
//     onAction: createLogger(),
//     onError(e: Error) {
//       message.error(e.message, 3);
//     },
//   },
// };